/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import com.zsmartsystems.zigbee.IeeeAddress;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspDeserializer;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember Structure <b>EmberBindingTableEntry</b>.
 * <p>
 * An entry in the binding table.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EmberBindingTableEntry {

    /**
     * The type of binding.
     * <p>
     * EZSP type is <i>EmberBindingType</i> - Java type is {@link EmberBindingType}
     */
    private EmberBindingType type;

    /**
     * The endpoint on the local node.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int local;

    /**
     * A cluster ID that matches one from the local endpoint's simple descriptor. This cluster ID is
     * set by the provisioning application to indicate which part an endpoint's functionality is
     * bound to this particular remote node and is used to distinguish between unicast and
     * multicast bindings. Note that a binding can be used to send messages with any cluster ID, not
     * just that listed in the binding.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     */
    private int clusterId;

    /**
     * The endpoint on the remote node (specified by identifier).
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int remote;

    /**
     * A 64-bit identifier. This is either the destination EUI64 (for unicasts) or the 64-bit group
     * address (for multicasts).
     * <p>
     * EZSP type is <i>EmberEUI64</i> - Java type is {@link IeeeAddress}
     */
    private IeeeAddress identifier;

    /**
     * The index of the network the binding belongs to.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int uint8_t;

    /**
     * Default Constructor
     */
    public EmberBindingTableEntry() {
    }

    public EmberBindingTableEntry(EzspDeserializer deserializer) {
        deserialize(deserializer);
    }

    /**
     * The type of binding.
     * <p>
     * EZSP type is <i>EmberBindingType</i> - Java type is {@link EmberBindingType}
     *
     * @return the current type as {@link EmberBindingType}
     */
    public EmberBindingType getType() {
        return type;
    }

    /**
     * The type of binding.
     *
     * @param type the type to set as {@link EmberBindingType}
     */
    public void setType(EmberBindingType type) {
        this.type = type;
    }

    /**
     * The endpoint on the local node.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current local as {@link int}
     */
    public int getLocal() {
        return local;
    }

    /**
     * The endpoint on the local node.
     *
     * @param local the local to set as {@link int}
     */
    public void setLocal(int local) {
        this.local = local;
    }

    /**
     * A cluster ID that matches one from the local endpoint's simple descriptor. This cluster ID is
     * set by the provisioning application to indicate which part an endpoint's functionality is
     * bound to this particular remote node and is used to distinguish between unicast and
     * multicast bindings. Note that a binding can be used to send messages with any cluster ID, not
     * just that listed in the binding.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     *
     * @return the current clusterId as {@link int}
     */
    public int getClusterId() {
        return clusterId;
    }

    /**
     * A cluster ID that matches one from the local endpoint's simple descriptor. This cluster ID is
     * set by the provisioning application to indicate which part an endpoint's functionality is
     * bound to this particular remote node and is used to distinguish between unicast and
     * multicast bindings. Note that a binding can be used to send messages with any cluster ID, not
     * just that listed in the binding.
     *
     * @param clusterId the clusterId to set as {@link int}
     */
    public void setClusterId(int clusterId) {
        this.clusterId = clusterId;
    }

    /**
     * The endpoint on the remote node (specified by identifier).
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current remote as {@link int}
     */
    public int getRemote() {
        return remote;
    }

    /**
     * The endpoint on the remote node (specified by identifier).
     *
     * @param remote the remote to set as {@link int}
     */
    public void setRemote(int remote) {
        this.remote = remote;
    }

    /**
     * A 64-bit identifier. This is either the destination EUI64 (for unicasts) or the 64-bit group
     * address (for multicasts).
     * <p>
     * EZSP type is <i>EmberEUI64</i> - Java type is {@link IeeeAddress}
     *
     * @return the current identifier as {@link IeeeAddress}
     */
    public IeeeAddress getIdentifier() {
        return identifier;
    }

    /**
     * A 64-bit identifier. This is either the destination EUI64 (for unicasts) or the 64-bit group
     * address (for multicasts).
     *
     * @param identifier the identifier to set as {@link IeeeAddress}
     */
    public void setIdentifier(IeeeAddress identifier) {
        this.identifier = identifier;
    }

    /**
     * The index of the network the binding belongs to.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current uint8_t as {@link int}
     */
    public int getUint8_t() {
        return uint8_t;
    }

    /**
     * The index of the network the binding belongs to.
     *
     * @param uint8_t the uint8_t to set as {@link int}
     */
    public void setUint8_t(int uint8_t) {
        this.uint8_t = uint8_t;
    }

    /**
     * Serialise the contents of the EZSP structure.
     *
     * @param serializer the {@link EzspSerializer} used to serialize
     */
    public int[] serialize(EzspSerializer serializer) {
        // Serialize the fields
        serializer.serializeEmberBindingType(type);
        serializer.serializeUInt8(local);
        serializer.serializeUInt16(clusterId);
        serializer.serializeUInt8(remote);
        serializer.serializeEmberEui64(identifier);
        serializer.serializeUInt8(uint8_t);
        return serializer.getPayload();
    }

    /**
     * Deserialise the contents of the EZSP structure.
     *
     * @param deserializer the {@link EzspDeserializer} used to deserialize
     */
    public void deserialize(EzspDeserializer deserializer) {
        // Deserialize the fields
        type = deserializer.deserializeEmberBindingType();
        local = deserializer.deserializeUInt8();
        clusterId = deserializer.deserializeUInt16();
        remote = deserializer.deserializeUInt8();
        identifier = deserializer.deserializeEmberEui64();
        uint8_t = deserializer.deserializeUInt8();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(175);
        builder.append("EmberBindingTableEntry [type=");
        builder.append(type);
        builder.append(", local=");
        builder.append(local);
        builder.append(", clusterId=");
        builder.append(String.format("%04X", clusterId));
        builder.append(", remote=");
        builder.append(remote);
        builder.append(", identifier=");
        builder.append(identifier);
        builder.append(", uint8_t=");
        builder.append(uint8_t);
        builder.append(']');
        return builder.toString();
    }
}
